package com.haller.testPlatform.util;

import kong.unirest.HttpResponse;
import kong.unirest.RequestBodyEntity;
import kong.unirest.Unirest;
import kong.unirest.UnirestInstance;

import java.util.Map;


/**
 * @Author harbour
 * @Description
 * @Date  11:54
 **/
public class HttpRequest {

    /**
     * @Author harbour
     * @Description //TODO
     * @Date 11:58 2021/6/20
     * @Param [url, headers, param]
     * @return java.lang.String
     **/
    public static String httpGetString(String url, Map<String, String> headers, Map<String, Object> param){
        String result = "";
        try{
            result = Unirest.get(url)
                    .headers(headers)
                    .queryString( param)
                    .asString().getBody();
        }catch (Exception e){
            e.printStackTrace();
            result = "请求出错"+ e.getMessage();
        }
        return result;
    }

    /**
     * @Author harbour
     * @Description //TODO
     * @Date 11:58 2021/6/20
     * @Param [url, headers, param]
     * @return java.lang.String
     **/
    public static String httpPostString(String url, Map<String, String> headers, Object body) {
        String result = "";
        try{
            result = Unirest.post(url)
                    .headers(headers)
                    .body(body)
                    .asString().getBody();
        }catch (Exception e){
            e.printStackTrace();
            result = "请求出错" + e.getMessage();
        }
        return result;
    }



}
